import { cloudService } from './index'
import { IFoodQuery, IFoodRecipe, IFoodRecord, IFoodStats } from '@/types/food'

export const addFoodRecipeApi = (foodRecipe: IFoodRecipe): Promise<boolean> =>
  cloudService({
    url: '/home-api/food/recipe',
    method: 'post',
    data: foodRecipe
  })

export const updateFoodRecipeApi = (id: number, foodRecipe: IFoodRecipe): Promise<boolean> =>
  cloudService({
    url: `/home-api/food/recipe/${id}`,
    method: 'put',
    data: foodRecipe
  })

export const deleteFoodRecipeApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/food/recipe/${id}`,
    method: 'DELETE'
  })

export const queryFoodRecipeByIdApi = (id: number): Promise<any> =>
  cloudService({
    url: `/home-api/food/recipe/${id}`,
    method: 'get'
  })

export const queryFoodRecipeApi = (currentPage: number, pageSize: number,
  query: IFoodQuery): Promise<any> =>
  cloudService({
    url: '/home-api/food/recipe/page',
    method: 'get',
    params: { currentPage, pageSize, ...query }
  })

export const queryFoodNameListApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/food/recipe/name',
    method: 'get'
  })

export const addFoodRecordApi = (foodRecord: IFoodRecord): Promise<boolean> =>
  cloudService({
    url: '/home-api/food/record',
    method: 'post',
    data: foodRecord
  })

export const updateFoodRecordApi = (id: number, foodRecord: IFoodRecord): Promise<boolean> =>
  cloudService({
    url: `/home-api/food/record/${id}`,
    method: 'put',
    data: foodRecord
  })

export const deleteFoodRecordApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/food/record/${id}`,
    method: 'DELETE'
  })

export const queryFoodRecordApi = (startDate: string, endDate: string): Promise<IFoodRecord[]> =>
  cloudService({
    url: '/home-api/food/record',
    method: 'get',
    params: { startDate, endDate }
  })

export const queryFoodCategoryApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/food/category',
    method: 'get'
  })

export const queryFoodStatsApi = (): Promise<IFoodStats> =>
  cloudService({
    url: '/home-api/food/stats',
    method: 'get'
  })
